// 表单校验规则由 schema2code 生成，不建议直接修改校验规则，而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
import message from '/pages/shop/i18n-shop/index.js'
const $w = (key) => {
	return message[uni.getLocale()][key]
}


const validator = {
	"ID": {
		"rules": [{
			"format": "string"
		}],
		"label": "ID"
	},
	"address": {
		"rules": [{
			"format": "object"
		}, {
			validateFunction: function(rule, value, data, callback) {
				if (!value.address_number.trim()) {
					callback('商户门牌号为必填')
					return false
				}

				if (/^(\d+)-(\d{2})-(\d{2})$/.test(value.address_number.trim())) {
					return true
				} else if (/^(\d+)-(D?\d{2})$/.test(value.address_number.trim())) {
					return true
				} else {
					callback('商户门牌号格式错误')
					return false
				}

				return true
			}
		}],
		"label": "地址"
	},
	"name": {
		"rules": [{
			"format": "object"
		}, {
			validateFunction: function(rule, value, data, callback) {
				if (!value["zh-Hans"].trim()) {
					callback($w('名称为必填'))
					return false
				}
				return true
			}
		}],
		"label": $w("名称")
	},
	"shop_desc": {
		"rules": [{
			"format": "object"
		}],
		"label": "简介"
	},
	"short_name": {
		"rules": [{
			"format": "object"
		}],
		"label": "公司简称"
	},
	"banner": {
		"rules": [{
			"format": "string"
		}],
		"label": "banner"
	},
	"logo_src": {
		"rules": [{
			"format": "string"
		}],
		"label": "LOGO"
	},
	"deliveryTypes": {
		"rules": [{
				"format": "array"
			},
			{
				"range": [{
						"text": "配送到家",
						"value": "deliveryHome"
					},
					{
						"text": "快递",
						"value": "express"
					},
					{
						"text": "到店/自提点自提",
						"value": "selfRaising"
					}
				]
			}
		],
		"defaultValue": "deliveryHome",
		"label": "配送方式"
	},
	"isPrint": {
		"rules": [{
			"format": "bool"
		}],
		"label": "是否开启打印"
	},
	"month_sell": {
		"rules": [{
			"format": "int"
		}],
		"label": "月售"
	},
	"online": {
		"rules": [{
			"format": "bool"
		}],
		"label": "是否营业"
	},
	"website": {
		"rules": [{
			"format": "string"
		}],
		"label": "公司官网"
	},
	"phone": {
		"rules": [{
			"format": "object"
		}],
		"label": "联系电话"
	},
	// "phone": {
	// 	"rules": [{
	// 		"format": "object"
	// 	}, {
	// 		validateFunction: function(rule, value, data, callback) {
	// 			if (value.head.trim() == '') {
	// 				callback('老板或负责人电话为必填')
	// 				return false
	// 			}
	// 			return true
	// 		}
	// 	}, {
	// 		validateFunction: function(rule, value, data, callback) {
	// 			const regex = /^(1[3-9]\d{9}|0991-\d{7})([,\s]*(1[3-9]\d{9}|0991-\d{7}))*$/;
	// 			if ( !regex.test(value.contact.trim()) && value.contact.trim().length>0) {
	// 				callback('对外销售电话格式有误！')
	// 				return false
	// 			}
	// 			if ( !regex.test(value.business.trim()) && value.business.trim().length>0) {
	// 				callback('商务合作电话格式有误！')
	// 				return false
	// 			}
	// 			return true
	// 		}
	// 	}],
	// 	"label": "联系电话"
	// },
	"score": {
		"rules": [{
			"format": "double"
		}],
		"label": "评分"
	},
	"serviceTime": {
		"rules": [{
			"format": "string"
		}],
		"label": "服务时间"
	},
	"src": {
		"rules": [{
			"format": "string"
		}],
		"label": "店铺logo"
	},
	"state": {
		"rules": [{
			"format": "bool"
		}],
		"label": "是否启用"
	}
}

const enumConverter = {
	"deliveryTypes_valuetotext": [{
			"text": "配送到家",
			"value": "deliveryHome"
		},
		{
			"text": "快递",
			"value": "express"
		},
		{
			"text": "到店/自提点自提",
			"value": "selfRaising"
		}
	]
}

export {
	validator,
	enumConverter
}